#pragma once
#include "math.h"
#include "esp_log.h"
#include "driver/i2c.h"
#include <stdint.h>
#include "ldg_i2c.h"

#define QMC5883L_SENSOR_ADDR 0x0D

typedef struct
{
  int16_t mag_x;
  int16_t mag_y;
  int16_t mag_z;
  float azimuth;
} t_sQMC5883L;

// 寄存器地址
enum qmc5883l_reg
{
  QMC5883L_XOUT_L,
  QMC5883L_XOUT_H,
  QMC5883L_YOUT_L,
  QMC5883L_YOUT_H,
  QMC5883L_ZOUT_L,
  QMC5883L_ZOUT_H,
  QMC5883L_STATUS,
  QMC5883L_TOUT_L,
  QMC5883L_TOUT_H,
  QMC5883L_CTRL1,
  QMC5883L_CTRL2,
  QMC5883L_FBR,
  QMC5883L_CHIPID = 13
};

extern void qmc5883l_init(void);

extern void qmc5883l_fetch_azimuth(t_sQMC5883L *p);